//
//  MyRankController.m
//  PosApp
//
//  Created by 刘萍 on 2018/9/12.
//  Copyright © 2018年 李英新. All rights reserved.
//

#import "MyRankController.h"
#import "MyRankView.h"
@interface MyRankController ()
@property (weak, nonatomic) IBOutlet UIScrollView *RankScrollView;

@end

@implementation MyRankController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"合伙人";
    
    MyRankView * RankV = [[NSBundle mainBundle] loadNibNamed:@"MyRankView" owner:self options:nil][0];
    RankV.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 950);
    [RankV.ShengJiBtn addTarget:self action:@selector(ClickOnBtnToShengJi) forControlEvents:UIControlEventTouchUpInside];
    [self.RankScrollView addSubview:RankV];
    self.RankScrollView.contentSize = CGSizeMake(0,CGRectGetMaxY(RankV.frame));
    
}

- (void)ClickOnBtnToShengJi{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
    [dic setObject:KUseriPhone forKey:@"phone"];
    
    [MainObjectWay PostWithMethod:@"level" andAction:@"Member" andAddParam:YES parameters:dic success:^(id responseObject) {
        
        NSLog(@"返回数据 = %@",responseObject);
        if ([MainObjectWay IsSucceedWithCode:responseObject[@"code"]]) {
            
            NSString * appScheme = @"2018041960010143";
            NSString * orderString = responseObject[@"data"];
            
            [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
                NSLog(@"支付宝结果 === %@",resultDic);
            }];
        }else{
            
            NSString * AlertStr = [NSString stringWithFormat:@"%@",responseObject[@"msg"]];
            UIAlertController * AlertC = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
            
            //修改message
            NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:AlertStr];
            [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, AlertStr.length)];
            [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, AlertStr.length)];
            [AlertC setValue:alertControllerMessageStr forKey:@"attributedMessage"];
            
            [AlertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"");
            }]];
            
            [self presentViewController:AlertC animated:YES completion:nil];
            
        }
    } failure:^(NSError *error) {
        NSLog(@"错误信息 = %@",error);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
